package Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import Entity.ProveNumEntity;
import Util.JdbcUtil;

public class ProveNumDao {
//	改
	public void update_refund(int refund_num){
		try {
			Connection conn = JdbcUtil.getConnection();
			String sql = "update provenum set refund_num='"+refund_num+"' where id=1;";
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.executeUpdate();
			JdbcUtil.close(pstmt, conn);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
//	改
	public void update_pay(int pay_num){
		try {
			Connection conn = JdbcUtil.getConnection();
			String sql = "update provenum set pay_num='"+pay_num+"' where id=1;";
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.executeUpdate();
			JdbcUtil.close(pstmt, conn);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
//	查
	public List<ProveNumEntity>select(){
		List<ProveNumEntity>list = new ArrayList<ProveNumEntity>();
		try {
			Connection conn = JdbcUtil.getConnection();
			String sql = "select * from provenum;";
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				ProveNumEntity num = new ProveNumEntity();
				num.setId(rs.getInt(1));
				num.setRefund_num(rs.getInt(2));
				num.setPay_num(rs.getInt(3));
				list.add(num);
			}
			JdbcUtil.close(pstmt, conn);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return list;
	}
}
